#include "chatcontent.h"
#include "ui_chatcontent.h"

chatContent::chatContent(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::chatContent)
{
    ui->setupUi(this);
}

chatContent::chatContent(QString name, QString id, QString time, QString content, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::chatContent)
{
    ui->setupUi(this);
    ui->content->setPlaceholderText(content);
    qDebug() << content;
    ui->content->adjustSize();
    ui->content->setDisabled(true);
    ui->labelName->setText(name);
    ui->labelName->adjustSize();
    ui->labelID->setText(id);
    ui->labelName->adjustSize();
    ui->labelTime->setText(time);
    ui->labelName->adjustSize();

}

chatContent::~chatContent()
{
    delete ui;
}

void chatContent::design(QString id){
    this->setStyleSheet(
                "QWidget{"
                    "background-color: rgba("+colorById(id.toInt())+"130);"
                    "border-width:1px;"
                    "border-radius:6px;"
                    "color:black"
                    "}"
                );
    //this->setWindowOpacity(0.3);
    UIDesign::setTransparent(ui->label);
    UIDesign::setTransparent(ui->labelID);
    UIDesign::setTransparent(ui->labelName);
    UIDesign::setTransparent(ui->labelTime);
    qDebug() << colorById(id.toInt());
}

QString chatContent::colorById(int i){

    if(i<10)i=i*302.3;
    if(i<100)i=i*31.2;
    for(;i>255;i*=0.98);

    QString temp=QString::number(i).left(QString::number(i).length()-3);
    i+=temp.toInt();
    for(;i>255;i-=255);
    i=qint32(i);
    if(i<10) i+=10;

    qint32 R=i*(i/100);
    for(;R>255;R-=255);
    if(R<50)R+=60;

    qint32 G=i*(i%100);
    for(;G>255;G-=255);
    if(G<50)G+=60;

    qint32 B=i*(i%10);
    for(;B>255;B-=255);
    if(B<50)B+=60;

    return QString::number(R)+","+QString::number(G)+","+QString::number(B)+",";
}
